﻿using Ardalis.ApiEndpoints;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using TodoList.Data;
using TodoList.Shared;

namespace TodoList.ArdalisEndpoints.Endpoints.TodoList;

public class GetList(ApplicationDbContext db) : EndpointBaseAsync
	.WithoutRequest
	.WithActionResult<IList<TodoItem>>
{
	[HttpGet("api/[namespace]")]
	public override async Task<ActionResult<IList<TodoItem>>> HandleAsync(CancellationToken cancellationToken = default)
	{
		var items = await db.TodoItems.ToListAsync(cancellationToken);
		return Ok(items);
	}
}
